C
@Ghofran-Daoues this is not really a question for this forum, it's really for a libmodbus forum. However, your error indicates it cannot connect to port 502 of the device. There can be a few reasons for this, the first things I would look at are 1) perhaps the device is not accessible on your network; 2) the device is not listening on port 502.
To check 1, see if you can ping the device (ping <ip address>)
To check 2, (assuming check 1 passes) check your modbus device is listening on port 502 using nmap (nmap -p 502 <ip address>) nmap should report the port is "open" but if it shows as closed, there's your problem, if it reports as "filtered" there is probably a firewall blocking you.